﻿@using WebApp.ViewModels.Manage;
@model UserLoginModel

@{
    Layout = "~/Views/Shared/_DialogLayout.cshtml";
}

@using (Html.BeginForm("Login", "Member", FormMethod.Post, new { @class = "form-horizontal form-inline", id = "inputform" }))
{
    <div class="dialog-content">
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        <table cellpadding="3" cellspacing="0" border="0" class="inputform">
            <tr>
                <td class="td-label">用户名</td>
                <td class="td-control">
                    @Html.TextBox("login_username", Session["Username"].ToString(), new { @class = "required", name = "username", id = "login_username", autocomplete = "off", style = "width:205px;padding:2px 3px;" })
                </td>
            </tr>
            <tr>
                <td class="td-label">密码</td>
                <td class="td-control">
                    @Html.Password("login_password", "", new { @class = "required", name = "password", id = "login_password", autocomplete = "off", style = "width:205px;padding:2px 3px;" })
                </td>
            </tr>
            <tr id="validatecode" style="display:none;">
                <td class="td-label">验证码</td>
                <td class="td-control">
                    @Html.TextBox("ValidateCode", new { @class = "required", name = "validatecode", id = "txtvalidatecode", autocomplete = "off", style = "width:118px;" })
                    <img src="~/Member/GetValidateCode" id="imgCode" alt="单击可刷新" style="margin-top:-10px;margin-left:5px;cursor:pointer;" title="点击换一张" onclick="ClickRemoveChangeCode()" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <div class="login_msg" style="display:none" id="errmsg"></div>
                </td>
            </tr>
        </table>
    </div>
    <div class="dialog-footer">
        @*<button id="btncancel" class="btn btn-small btn-default">退出</button>*@
        <button id="btnlogin" class="btn btn-small btn-primary">登录</button>
    </div>
}

@section scripts {

<script type="text/javascript">
    var msg = "@ViewBag.msg";
    var msgpwd = "@ViewBag.msgpwd";
    var msgcode = "@ViewBag.msgcode";
    var isvalidate = "@ViewBag.IsValidate";
    $(document).ready(function () {

        $("#btnlogin").click(function (e) {
            e.preventDefault();

            parent.relogin = true;
            parent.dlglogin.close();
        });

        //debugger;
        $('#login_username').focus();
        var errlist = [];
        if (isvalidate == "True") {
            // debugger;
            $('#validatecode').show();
            $('#validatecode').val("");
            $(".login_plat").find("p").each(function () {
                $(this).toggleClass("top10");
                $(this).toggleClass("top1");
            });
        }
        else {
            //debugger;
            $('#validatecode').hide();
            $('#validatecode').val("");
        }

        if (msg != null && msg != "") {
            errlist.push(msg);
        }
        if (msgpwd != null && msgpwd != "") {
            errlist.push(msgpwd);
        }
        if (msgcode != null && msgcode != "") {
            errlist.push(msgcode);
        }

        var errhtml = "";
        if (errlist.length > 0) {

            $('#validatecode').show();
            $('#txtvalidatecode').val("");
            $(".login_plat").find("p").each(function () {
                $(this).attr("style", "padding:1px;");
            });

            $("#errmsg").attr("style", "display:block;");
            for (var i = 0; i < errlist.length; i++) {
                errhtml += "<span style=\"font-size:9pt;color:#d91212;\">" + errlist[i] + "</span><br />";
            }
            $("#errmsg").html(errhtml);

        }
        else {
            $("#errmsg").attr("style", "display:none;");
            $("#errmsg").html("");
        }
    });

    function ClickRemoveChangeCode() {
        var code = $("#imgCode").attr("src");
        $("#imgCode").attr("src", "@Href("~/")Member/GetValidateCode?random=" + Math.random());
    }
</script>

} 